
package com.hjk.common.response.exception;


import com.hjk.common.response.enums.ErrorCodeEnum;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.time.LocalDateTime;

/**
 * 基本异常.
 *
 * @author huangjunkai
 */
@Slf4j
@Data
public class BaseException extends RuntimeException {

	/**
	 * 异常码
	 */
	protected int code;
	protected String msg;
	protected LocalDateTime date = LocalDateTime.now();


	public static void main(String[] args) {
		BaseException aa = new BaseException("哈哈哈");
		System.out.println(aa);
	}
	private static final long serialVersionUID = 3160241586346324994L;

	public BaseException() {
	}

	public BaseException(Throwable cause) {
		super(cause);
	}

	public BaseException(String message) {
		this.msg = message;
		this.code = 200;
	}

	public BaseException(String message, Throwable cause) {
		super(message, cause);
	}

	public BaseException(int code, String message) {
		super(message);
		this.code = code;
	}

	public BaseException(int code, String msgFormat, Object... args) {
		super(String.format(msgFormat, args));
		this.code = code;
	}

	public BaseException(ErrorCodeEnum codeEnum, Object... args) {
		super(String.format(codeEnum.msg(), args));
		this.code = codeEnum.code();
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}
}
